home *** CD-ROM | disk | FTP | other *** search
- 10 'STUDENT.BAS - From the GWBT (GW-Basic Tutorial) Series
- 20 'Lesson 10, 04/01/1991 Illustrating the use of RANDOM file types
- 30 '
- 40 'We are dealing with a set of data as shown:
- 50 '
- 60 'SNAME$ - Student last name, 18 alphabetic characters
- 70 'STUDENTID# - Student ID Code
- 80 'COURSECODE% - Student's Course ID Code
- 90 'GPA! - Student's Grade Point Average
- 100 '
- 110 'We'll be storing these in a RANDOM disk file in that order:
- 120 '
- 130 OPEN "STUDENT.DAT" FOR RANDOM AS #1 LEN=32
- 140 FIELD #1,18 AS STUDNAME$,8 AS STUDID$,2 AS STUDCC$,4 AS STUDGPA$
- 150 '
- 160 'NOTE that all the fields are set up as STRINGS - This is how we will be
- 170 'storing the information to disk following the conversion...
- 180 '
- 190 KEY OFF:COLOR 6,0,0:CLS
- 200 PRINT "Press 'R' to read in a student's information from disk, 'W' to"
- 210 PRINT "enter and write a student's information to disk, or 'Q' to quit..."
- 220 AA$=INKEY$
- 230 IF AA$="Q" OR AA$="q" THEN CLOSE:RESET:END
- 240 IF AA$="R" OR AA$="r" THEN GOTO 300
- 250 IF AA$="W" OR AA$="w" THEN GOTO 520
- 260 GOTO 220
- 270 'The above will end the program if Q is pressed, go to line 300 or 400 as
- 280 'above; if the key is not Q, R, or W it will go back to 220 and get another
- 290 'key press...
- 300 'Choice = "R" (Read in Student Information)
- 310 CLS
- 320 PRINT "To find a student's information on disk, I need you to give me the"
- 330 PRINT "Student ID code. Please enter it below..."
- 340 PRINT
- 350 INPUT "Student ID: ",STUDENTID#
- 360 PRINT
- 370 PRINT "Looking, please wait..."
- 380 EN1=LOF(1)/32
- 390 FOR RECORD = 1 TO EN1
- 400 GET #1,RECORD
- 410 SID# = CVD(STUDID$)
- 420 IF SID# <> STUDENTID# THEN GOTO 480
- 430 PRINT "Information is as follows:"
- 440 PRINT "Student Last Name: ";STUDNAME$
- 450 PRINT "Student ID Code : ";SID#
- 460 PRINT "Course Code : ";CVI(STUDCC$)
- 470 PRINT "Student GPA : ";CVS(STUDGPA$)
- 480 NEXT RECORD
- 490 PRINT "Search complete. Press any key to continue..."
- 500 WHILE INKEY$="":WEND
- 510 GOTO 190
- 520 'Choice - "W" (Write information to disk)
- 530 PRINT
- 540 PRINT "Please provide the requested information below..."
- 550 PRINT
- 560 LINE INPUT "Student Last Name: ";SNAME$
- 570 INPUT "Student ID Code : ";STUDENTID#
- 580 INPUT "Course Code : ";COURSECODE%
- 590 INPUT "Student GPA : ";STUDENTGPA!
- 600 PRINT
- 610 PRINT "If all of the above is correct, press 'Y' to save to disk, or else
- 620 PRINT "press 'N' to start over again..."
- 630 AA$=INKEY$
- 640 IF AA$="Y" OR AA$="y" THEN GOTO 670
- 650 IF AA$="N" OR AA$="n" THEN GOTO 540
- 660 GOTO 630
- 670 EN1=LOF(1)/32 + 1
- 680 LSET STUDNAME$ = SNAME$
- 690 LSET STUDID$ = MKD$(STUDENTID#)
- 700 LSET STUDCC$ = MKI$(COURSECODE%)
- 710 LSET STUDGPA$=MKS$(STUDENTGPA!)
- 720 PUT #1,EN1
- 730 GOTO 190